<template>
  <div class="page maintainInspect-page" id="maintainInspect-page_{{getNewId}}" data-page="maintainInspect"
    style="z-index: 2;">
    <div class="link-page-nav">
      <a href="#" class="link" @click=$root.backToTab()>
        <i class="iconfont icon-zuo"></i>
      </a>
    </div>
    <div class="link-page-top">
      <div class="link-page-title fl">维保巡查</div>
      <div class="link-page-search">
        <div class="link-page-search-input" style="width: 50%;">
          <i class="iconfont icon-APPicon_sousuo1"></i>
          <input type="text" placeholder="搜一搜" id="dectorsearch-contantInfo_{{getNewId}}">
        </div>
      </div>
      <a href="#" class="link popover-open" data-popover="#maintainInspect_menu_{{getNewId}}" style="color: #000;">
        <i class="iconfont icon-APPicon_shaixuan1
" id="active_{{getNewId}}" style="font-size: 23px;"></i>
      </a>
    </div>
    <div class="link-page-tab">
      <div class="checkApply-tab">
        <a href="#" class="checkApply-link" @click="updateListView(1)">未开始</a>
        <a href="#" class="checkApply-link" @click="updateListView(2)">进行中</a>
        <a href="#" class="checkApply-link" @click="updateListView(3)">已结束</a>
      </div>
    </div>
    <div class="page-content pdbottom100 ptr-content infinite-scroll-content"
      id="pageContent_maintainInspect_{{getNewId}}" @ptr:refresh="refreshCurrentList" data-infinite-distance="50"
      @infinite="loadMoreList">
      <div class="ptr-preloader" style="top: -10px;">
        <div class="preloader color-multi"></div>
        <div class="ptr-arrow"></div>
      </div>
      <div class="list media-list">
        <ul id="maintainInspectList_{{getNewId}}"></ul>
        <div id="maintainInspectList_preloader_{{getNewId}}" class="preloader infinite-scroll-preloader"></div>
      </div>
    </div>
    <div class="popover select-option-list" id="maintainInspect_menu_{{getNewId}}" style="width: 160px;top: 60px;">
      <div class="popover-angle"></div>
      <div class="popover-inner">
        <div class="list">
          <ul>
            <li>
              <a href="#" class="list-button item-link popover-close"
                id="maintainInspect_select_org_{{getNewId}}">选择单位</a>
            </li>
            <li>
              <a href="#" class="list-button item-link popover-close"
                id="maintainInspect_select_owner_{{getNewId}}">选择责任人</a>
            </li>
            <li>
              <a href="#" class="list-button item-link popover-close"
                id="maintainInspect_select_progressRange_{{getNewId}}" @click="workPeriodFun">周期</a></li>
            <li>
            <li>
              <a href="#" class="list-button item-link popover-close" id="maintainInspect_select_dateRange_{{getNewId}}"
                @click="getTbTime" style="display: none;">选择日期范围</a>
            </li>
            <li id="select_status_{{getNewId}}" style="height:48px;">
              <a href="#" class="list-button item-link popover-close statusFilter"
                id="maintainInspect_select_complete_{{getNewId}}" @click="filterStatus(1)">已完成</a>
              <a href="#" class="list-button item-link popover-close statusFilter"
                id="maintainInspect_select_notComplete_{{getNewId}}" @click="filterStatus(0)">未完成</a>
            </li>
            <li>
              <a href="#" class="list-button item-link popover-close removeScreen select-active"
                @click="removeScreen">清&nbsp&nbsp&nbsp&nbsp&nbsp空</a>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="toolbar tabbar tabbar-labels toolbar-bottom-md" id="maintain_bottom_nav_{{getNewId}}"
      style="height: 60px;z-index: 9999;bottom:-1px !important;display:none;">
      <div class="toolbar-inner">
        <div class=" selectAll">
          <label class="checkbox" for="selectAll_{{getNewId}}">
            <input type="checkbox" value="0" id="selectAll_{{getNewId}}"/>
            <i class="icon-checkbox" style="    display: inline-block;
            vertical-align: middle;"></i>
            <span style="    display: inline-block;
            vertical-align: middle;">全选</span>
          </label>
        </div>
        <a href="#" id="homeReset_{{getNewId}}" class="tab-link">
          <span class="selectNum">已选选择 <i id="selectCheckNum_{{getNewId}}">0</i> 个</span>
        </a>
        <a href="#" @click="addOwner" class="tab-link">
          <div class="addOwnerBtn">添加责任人</div>
        </a>
      </div>
    </div>
  </div>
</template>
<style>
  .workPerActive {
    font-weight: bold;
    color: #378bf6;
  }
</style>
<style scoped>
  .item-title-row {
    font-weight: bold;
  }
</style>
<script>
  return {
    mounted() {
      var self = this;
      var $ = self.$;
      self.selectIndex = self.$route.params.tabID;
      self.selectorgid = self.$route.params.orgid;

      // 选中单位
      var theOrg=currentUserUnitListData.filter(n=>{ return n.organizationId==self.selectorgid})[0]
      if(theOrg){
          jQuery("#maintainInspect_select_org_"+self.getNewId).html(theOrg.shortName);
          jQuery("#maintainInspect_select_org_"+self.getNewId).addClass('select-active');
      }
    },
    data: function () {
      return {
        getNewId: (new Date()).getTime(),
        pageName: "maintainInspect",
        pageSize: 25,//分页参数(每页显示条数)
        pageIndex: 0,//分页参数
        orgIds: 0,//联网单位编码，支持多单位，逗号拼接
        status: 2,//任务状态  0:全部  1：未开始 2：进行中 3：已结束
        taskTitle: '',//任务名称
        maintainAccount: '',//责任人账号
        selectOptionOrg: '',
        currentOrgId: '',
        startPercent: '',//结束完成度
        endPercent: '',//开始完成度
        startTime: '',//开始日期 yyyy-MM-dd格式
        endTime: '',//任结束日期 yyyy-MM-dd格式
        finishStatus: '', //进行中查询的状态
        taskIds: '', //选中的任务ID
        selectOptionIndex: '',
        allowInfinite: true,
        touBType: [],
        saveListOwner: [],
        orgidArr: [],			//单位ID ，用户判断选中的任务是否是多个单位的任务
        selectOptionIndex1: null,
        selectOptionType: null,
        workPeriod:0,
        gradeselectOptionIndex:''
      }
    },
    methods: {
      backToRefresh: function () {
        var self = this;
        self.updateListView(self.status);
        $("#selectCheckNum_" + self.getNewId).html(0);
      },
      // 周期选择类型
      workPeriodFun: function () {
        let self=this;
        let touBType = [{ id: 1, name: '月' }, { id: 2, name: '季度' }, { id: 3, name: '半年' }, { id: 4, name: '年' }]
        selectOptionFn(touBType, function (data) {
          if (self.workPeriod == data.id) {
            jQuery("#maintainInspect_select_progressRange_"+self.getNewId).html("周期");
            jQuery("#maintainInspect_select_progressRange_"+self.getNewId).removeClass('select-active');
            self.workPeriod = 0;
          } else {
            jQuery('#maintainInspect_select_progressRange_' + self.getNewId).html(data.name);
            jQuery('#maintainInspect_select_progressRange_' + self.getNewId).addClass('select-active');
            self.workPeriod = data.id;
          }
          if(self.gradeselectOptionIndex != data.index){
                self.gradeselectOptionIndex = data.index;
            }else{
                self.gradeselectOptionIndex = "";
            }
            jQuery("#maintainInspectList_" + self.getNewId).empty();
            self.pageIndex=0
            self.getMaintainList()
        },self.gradeselectOptionIndex);

      },

      /*区分联网单位*/
      isMuilUnitUser: function () {
        let self = this;
        //单联网单位
        if (userInfor.isMuilUnitUser == 0) {
          self.currentOrgId = userInfor.organizationIds;
          $("#maintainInspect_select_org_" + self.getNewId).hide();
        } else {
          //多联网单位
          if (single_Orgid == "") {
            self.currentOrgId = userInfor.organizationIds;
          } else {
            self.currentOrgId = single_Orgid;
          }
          jQuery("#maintainInspect_select_org_" + self.getNewId).show().click(function (e) {
            loadSelectUnitFunc(function (data) {
              //筛选选中联网单位
              if (self.selectOptionOrg != data.orgId) {
                self.selectOptionOrg = data.orgId;
                self.currentOrgId = data.orgId;
                jQuery("#maintainInspect_select_org_" + self.getNewId).html(data.orgName).addClass('select-active');
              } else {
                self.selectOptionOrg = '';
                self.currentOrgId = userInfor.organizationIds;
                jQuery("#maintainInspect_select_org_" + self.getNewId).html("选择单位").removeClass('select-active');
                jQuery("#maintainListTitle_" + self.getNewId).html("保养");
              }
              self.cleanUser();
              self.pageIndex = 0;
              jQuery("#maintainInspectList_" + self.getNewId).empty();
              //self.reInit();
              self.getMaintainList();
            }, self.selectOptionOrg);
          });
        }
      },
      /*责任人*/
      initResponsPeople: function () {
        let self = this;
        self.selectOptionIndex1 = null;
        self.selectOptionType = null;
        //人员名单
        jQuery("#maintainInspect_select_owner_" + self.getNewId).click(function (e) {
          /* if(!self.currentOrgId || self.currentOrgId.toString().split(",").length != 1){
              app.methods.showToastCenter('请选择单位');
              return;
          } */
          getFourTypeUser(self.currentOrgId, function (data) {
            //这里是选择责任人之后的回调
            if (self.selectOptionIndex1 != data.index) {
              self.selectOptionIndex1 = data.index;
              self.selectOptionType = data.type;
              //维保公司
              // if(data.type == 4){
              //   self.maintainAccount = '';
              // }else{
              //   self.maintainAccount = data.index;
              // }
              self.maintainAccount = data.index;
              $("#maintainInspect_select_owner_" + self.getNewId).addClass('select-active').html(data.name);
            } else {
              self.selectOptionIndex1 = "";
              self.selectOptionType = 1;
              self.maintainAccount = "";
              $("#maintainInspect_select_owner_" + self.getNewId).removeClass('select-active').html("选择责任人");
            }
            jQuery("#maintainInspectList_" + self.getNewId).empty();
            self.pageIndex = 0;
            //self.reInit();
            self.getMaintainList();
          }, self.selectOptionIndex1, self.selectOptionType);
        });
      },
      //清除责任人相关参数
      cleanUser: function () {
        var self = this;
        self.selectOptionIndex1 = null;
        self.selectOptionType = null;
        self.maintainAccount = "";
        jQuery("#maintainInspect_select_owner_" + self.getNewId).removeClass('select-active').html("选择责任人");
      },
      dealNode: function (re) {
        let self = this;
        for (var i = 0; i < re.length; i++) {
          let obj = {};
          obj.id = re[i].id;
          obj.name = re[i].name;
          obj.type = 'weibaogongsi';
          self.touBType.push(obj);
          if (re[i].nodes && re[i].nodes.length > 0) {
            self.dealNode(re[i].nodes);
          }
        }
      },
      updateListView: function (status) {
        if (getClickEnabel()) {
          let self = this;
          let $ = self.$$;
          self.status = status;
          //选择框变色
          $("#maintainInspect-page_" + self.getNewId + " .checkApply-link").removeClass('active').eq((status - 1)).addClass('active');
          $(".checkApply-page .tab-link-highlight").css("left", ((status - 1) == 0 ? 1 : (status - 1) * 33.3333) + "%");
          jQuery("#pageContent_maintainInspect_" + self.getNewId).removeClass('pdbottom140');
          //定制筛选条件
          if (self.status == 1) {
            $("#maintain_bottom_nav_" + self.getNewId).show();
            jQuery("#pageContent_maintainInspect_" + self.getNewId).addClass('pdbottom140');
            //$("#maintainInspect_select_progressRange_" + self.getNewId).hide();
            $("#maintainInspect_select_dateRange_" + self.getNewId).hide();
            $("#select_status_" + self.getNewId).hide();
            //初始化未开始全选
            self.initNoStart();
          } else if (self.status == 2) {
            $("#select_status_" + self.getNewId).show();// 状态
            $("#maintain_bottom_nav_" + self.getNewId).hide();//添加责任人
            //$("#maintainInspect_select_progressRange_" + self.getNewId).hide();
            $("#maintainInspect_select_dateRange_" + self.getNewId).hide();
          } else if (self.status == 3) {
            $("#maintain_bottom_nav_" + self.getNewId).hide();
            $("#maintainInspect_select_dateRange_" + self.getNewId).show();
            //$("#maintainInspect_select_progressRange_" + self.getNewId).show();
            $("#select_status_" + self.getNewId).hide();
          }
          self.pageIndex = 0;
          $("#maintainInspectList_" + self.getNewId).empty();
          //展示列表数据
          //self.reInit();
          self.getMaintainList();
        }
      },
      /*下拉刷新*/
      refreshCurrentList: function (e, done) {//刷新功能
        let self = this;
        let $ = self.$$;
        if (done && e) {
          setTimeout(function () {
            jQuery("#maintainInspectList_" + self.getNewId).empty();
            self.pageIndex = 0;
            //self.reInit();
            self.getMaintainList();
            done();
          }, 1000);
        }
      },
      reInit: function () {
        var self = this;
        self.pageIndex = 0;
        $("#selectAll").prop("checked", false);
        if (app.view.current.router.url.indexOf('/maintainInspect/') > -1) {//防止子页面返回触发。有类似的需求可以往这个里面添加
          $("#pageContent_maintainInspect_" + self.getNewId).scrollTop(0, 300);
        }
        $("#maintainInspectList").empty();
        if (!self.allowInfinite) {
          self.allowInfinite = true;
          $('#maintainInspectList_preloader').show();
        }
      },
      /*上拉加载*/
      loadMoreList: function () {
        let self = this;
        if (!self.allowInfinite) return;
        self.allowInfinite = false;
        setTimeout(function () {
          self.pageIndex++;
          self.getMaintainList();
          self.allowInfinite = true;
        }, 1000);
      },
      getMaintainList: function () {
        let self = this;
        let $ = self.$$;
        //筛选按钮有值变色
        if (jQuery('#maintainInspect_select_progressRange_'+ self.getNewId)[0].innerText!='周期'||jQuery("#maintainInspect_select_owner_" + self.getNewId)[0].innerText != "选择责任人" || self.startTime != "" || self.startPercent != "" || self.finishStatus != "" || self.finishStatus === 0 || jQuery("#maintainInspect_select_org_" + self.getNewId)[0].innerText != "选择单位") {
          jQuery("#active_" + self.getNewId).addClass("select-active");
        } else {
          jQuery("#active_" + self.getNewId).removeClass("select-active");
        }
        self.saveListOwner = [];
        Dao.getMainTainTaskList({
          queryType: 1,//分页参数 0：不分页 1：分页
          pageSize: self.pageSize,//分页参数(每页显示条数)
          pageIndex: self.pageIndex,//分页参数
          orgIds: self.currentOrgId,//self.currentOrgId  122 测试数据先写死  联网单位编码，支持多单位，逗号拼接  
          status: self.status,//任务状态 1：未开始 2：进行中 3：已结束
          maintainAccount: self.maintainAccount,//责任人账号
          name: self.taskTitle,//任务名称
          startPercent: self.startPercent,//开始完成度
          endPercent: self.endPercent,//结束完成度
          startTime: self.startTime,//开始日期 yyyy-MM-dd格式
          endTime: self.endTime,//任结束日期 yyyy-MM-dd格式
          finishStatus: self.finishStatus,
          maintainType: 1,  //1 维保巡查任务 2保养任务 3测试任务 4联动测试任务
          account: userInfor.accountName,
          workPeriod:self.workPeriod
        }, function (data, total) {
          if (data && data.length > 0) {
            if (self.pageSize * self.pageIndex + data.length < total) { //有分页
              $("#maintainInspectList_preloader_" + self.getNewId).show();
              self.allowInfinite = true;
            } else {
              //没分页
              $("#maintainInspectList_preloader_" + self.getNewId).hide();
              self.allowInfinite = false;
            }
            for (let i = 0; i < data.length; i++) {
              //保存责任人账号
              if (data[i].maintainAccount) {
                let arr = data[i].maintainAccount.split(",");
                self.saveListOwner[data[i].id] = data[i].maintainAccount;
              }
              let maintainNames = data[i].maintainNames == null ? "无" : data[i].maintainNames;//任务责任人名称
              let assetsCount = data[i].assetsCount; //资产数量
              let finishCount = data[i].finishCount; //维保完成数量
              let percentageNum = ((finishCount / assetsCount) * 100).toFixed(0);
              let percentageRealNum = percentageNum - 100;
              let percentage = percentageNum.toString() + "%";
              let orgNameHtml = "";
              let status = "未完成";
              let statusCSS = "title-status-notComplete";
              if (percentage == "100%") {
                status = "完成";
                statusCSS = "title-status-complete";
              }
              if (userInfor.isMuilUnitUser == 1) {
                orgNameHtml = `<div class="item-subtitle decter-belong-unit">
                                    <i class="iconfont icon-dingweiweizhi" style="color: #2471CA;font-size: 14px;"></i>
                                    `+ data[i].orgName + `
                                  </div>`;
              }
              if (self.status == 2) {//进行中的任务
                $("#maintainInspectList_" + self.getNewId).append(`
                      <li style="overflow:hidden">
                        <a href="/maintainInspectDetail/`+ data[i].id + `/0/" class="item-link item-content" data-view=".view-main">
                          <div class="item-inner">
                            <div class="item-title-row">`+ data[i].name + `</div>
                            <div class="item-subtitle decter-mesage">
                              <div class="ilink-progress-len-title">完成进度</div>
                              <div class="ilink-progress-len">
                                  <div class="ilink-progress-left">
                                    <div data-progress="80" class="progressbar color-blue progressbar-height">
                                      <span style="transform: translate3d(`+ percentageRealNum + `%, 0px, 0px);" class=""></span>
                                    </div>
                                  </div>
                                  <div class="progressbarNum">`+ percentage + `</div>
                              </div> 
                            </div>
                            <div class="item-subtitle decter-mesage">责&nbsp;&nbsp;任&nbsp;&nbsp;人&nbsp;&nbsp;   `+ maintainNames + `</div>
                            `+ orgNameHtml + `
                          </div>
                        </a>
                        <div class="decter-stuts-con" style="padding-left: 15px; border-top:0">
                          <span class="left">
                            <span>`+ isDay(data[i].remainTime) + `</span>
                          </span>
                        
                        </div>
                        <div >  <span class="right" style="float:right;margin-right:15px;margin-bottom:15px;border-radius: 15px;background:#397ECE;width: 80px;
    font-size: 12px;">
                              <a href="#" id="mainTask_`+ (self.getNewId + '_' + data[i].id) + `" style="color:#fff;display: block;
    padding: 5px 15px;" data-view=".view-main" ></a>
                          </span></div>
                      </li>`);
                if (percentage == "100%") {
                  $("#mainTask_" + (self.getNewId + '_' + data[i].id)).parent('span').hide();
                } else {
                  var dataTask = {
                    "id": data[i].id,
                    "orgId": data[i].orgId,
                    "orgName": data[i].orgName,
                    "name": data[i].name,
                    "status": data[i].status,
                    "testTaskStatus": data[i].testTaskStatus,
                    "maintainAccount": data[i].maintainAccount,
                  };
                  self.sortMainTask(dataTask);
                }

              }
              else if (self.status == 1) {//未开始的任务
                $("#maintainInspectList_" + self.getNewId).append(`
                          <li>
                            <a href="/maintainInspectDetail/`+ data[i].id + `/0/" class="item-link item-content" data-view=".view-main">
                              <div class="item-inner">
                                <div class="item-title-row">`+ data[i].name + `</div>
                                <div class="item-subtitle decter-mesage">
                                  <div style="float: left;">任务周期</div>
                                  <div class="taskCycleDate">`+ data[i].startTimeStr + `~` + data[i].endTimeStr + `</div>
                                </div>
                                <div class="item-subtitle decter-mesage">责&nbsp;&nbsp;任&nbsp;&nbsp;人&nbsp;&nbsp;   `+ maintainNames + `</div>
                                `+ orgNameHtml + `
                              </div>
                            </a>
                            <div class="decter-stuts-con" style="padding-left: 15px;">
                              <span class="left">
                                <label class="checkbox">
                                  <input type="checkbox" value="`+ data[i].id + `" data-orgid="` + data[i].orgId + `"/>
                                    <i class="icon-checkbox"></i>
                                  </label>
                              </span>
                              <span class="startTime">`+ data[i].remainTime + `&nbsp;后开始</span>
                            </div>
                          </li>`);
                self.getSelectCheckBox();
              }
              else if (self.status == 3) {//已完成的任务
                $("#maintainInspectList_" + self.getNewId).append(`
                          <li>
                          <a href="/maintainInspectDetail/`+ data[i].id + `/0/" class="item-link item-content" data-view=".view-main">
                            <div class="item-inner">
                              <div class="`+ statusCSS + `">` + status + `</div>
                              <div class="item-title-row protect-title">`+ data[i].name + `</div>
                              <div class="item-subtitle decter-mesage">
                                <div style="float: left;">完成进度</div>
                                <div class="ilink-progress-len">
                                  <div class="ilink-progress-left">
                                    <div data-progress="80" class="progressbar color-blue progressbar-height">
                                      <span style="transform: translate3d(`+ percentageRealNum + `%, 0px, 0px);" class=""></span>
                                    </div>
                                  </div>
                                  <div class="progressbarNum">`+ percentage + `</div>
                                </div> 
                              </div>
                              <div class="item-subtitle decter-mesage">
                              <div style="float: left;">任务周期</div>
                              <div class="taskCycleDate">`+ data[i].startTimeStr + `~` + data[i].endTimeStr + `</div>
                            </div>
                              <div class="item-subtitle decter-mesage">责&nbsp;&nbsp;任&nbsp;&nbsp;人&nbsp;&nbsp;   `+ maintainNames + `</div>
                              `+ orgNameHtml + `
                            </div>
                          </a>
                        </li>`);
              }
            }
          } else {
            self.allowInfinite = false;
            $("#maintainInspectList_preloader_" + self.getNewId).hide();
            if (self.pageIndex == 0) {
              jQuery("#maintainInspectList_" + self.getNewId).empty().append(`<div class="no-data-img"><img src="` + listNoDataPic() + `"/></div>`);
            }
          }
        });
      },
      sortMainTask: function (data) {
        var self = this;
    
        if (data.maintainAccount.indexOf(userInfor.accountName) >= 0) {//当前登录人是责任人

          if (data.testTaskStatus == 0) { //开始保养
            $("#mainTask_" + (self.getNewId + '_' + data.id)).html(`开始巡查`);
          } else {  // 继续保养
            $("#mainTask_" + (self.getNewId + '_' + data.id)).html(`继续巡查`);
          }
        } else {
          $("#mainTask_" + (self.getNewId + '_' + data.id)).parent('span').hide();
        }
        jQuery("#mainTask_" + (self.getNewId + '_' + data.id)).off().click(data, function (e) {
          if (e.data.testTaskStatus == 0) {
            Dao.startTestTask({
              taskId: e.data.id,
              account: userInfor.accountName
            }, function (data) {
              app.methods.showToastCenter("加入成功");
              self.getMaintainList();  // 刷新列表数据
              custom.startMaintenancePlan();
              app.router.navigate(`/allBuild/maintainInspect/` + e.data.id + `/` + e.data.orgName + `/` + encodeURIComponent(e.data.name) + `/` + e.data.status + `/` + e.data.orgId + `/`);
            }, true);
          } else {
            app.router.navigate(`/allBuild/maintainInspect/` + data.id + `/` + data.orgName + `/` + encodeURIComponent(data.name) + `/` + data.status + `/` + data.orgId + `/`);
          }
        });
      },
      //全选
      initNoStart: function () {
        let self = this;
        $("#selectAll_" + self.getNewId).change(function () {
          self.taskIds = "";
          self.orgidArr = [];
          if ($("#selectAll_" + self.getNewId).prop("checked")) {
            $("#maintainInspectList_" + self.getNewId + " input[type=checkbox]").prop("checked", true);
            $("#selectCheckNum_" + self.getNewId).html($("#maintainInspectList_" + self.getNewId + " input[type=checkbox]").length);
          } else {
            $("#maintainInspectList_" + self.getNewId + " input[type=checkbox]").prop("checked", false);
            $("#selectCheckNum_" + self.getNewId).html(0);
          }
          let checkOwner = $("#maintainInspectList_" + self.getNewId + " input:checked");
          let taskIdsStr = ""
          for (let i = 0; i < checkOwner.length; i++) {
            let taskId = $(checkOwner[i]).val();
            self.orgidArr.push($(checkOwner[i]).attr("data-orgid"));
            if (i < checkOwner.length - 1) {
              taskId = taskId + ",";
            }
            self.taskIds += taskId;
          }
        });
      },
      //单个复选框选中事件
      getSelectCheckBox: function () {
        let self = this;
        self.taskIds = "";
        $("#selectAll_" + self.getNewId).prop("checked", false);
        $("#maintainInspectList_" + self.getNewId + " .checkbox input").change(function (e) {
          self.taskIds = "";
          self.orgidArr = [];
          let chks = $("#maintainInspectList_" + self.getNewId + " input:checked").length;
          $("#selectCheckNum_" + self.getNewId).html(chks);
          if ($("#maintainInspectList_" + self.getNewId + " input[type=checkbox]").length == chks) {
            $("#selectAll_" + self.getNewId).prop("checked", true);
          } else {
            $("#selectAll_" + self.getNewId).prop("checked", false);
          }

          let checkOwner = $("#maintainInspectList_" + self.getNewId + " input:checked");
          let taskIdsStr = ""
          for (let i = 0; i < checkOwner.length; i++) {
            self.orgidArr.push($(checkOwner[i]).attr("data-orgid"));
            let taskId = $(checkOwner[i]).val();
            if (i < checkOwner.length - 1) {
              taskId = taskId + ",";
            }
            self.taskIds += taskId;
          }
        });
      },
      /*初始化搜索*/
      initEnter: function () {
        let self = this;
        jQuery("#dectorsearch-contantInfo_" + self.getNewId).keypress(function (e) {
          let name = jQuery("#dectorsearch-contantInfo_" + self.getNewId).val();
          if (e.which == 13) {
            jQuery("#maintainInspectList_" + self.getNewId).empty();
            self.taskTitle = name;
            self.pageIndex = 0;
            self.getMaintainList();
          };
        });
      },
      addOwner: function () {
        let self = this;
        if (self.taskIds == "") {
          app.methods.showToastCenter('请选择任务');
          return;
        } else {
          var tempOrgids = [];
          for (var i = 0; i < self.orgidArr.length; i++) {
            if (self.orgidArr.indexOf(self.orgidArr[i]) == i) {
              tempOrgids.push(self.orgidArr[i]);
            }
          }
          //如果用户选择了多个单位的维保任务，则提示用户“请选择同一单位的维保任务”;
          if (tempOrgids.length > 1) {
            app.methods.showToastCenter('请选择同一单位的维保任务');
            return;
          }
          app.router.navigate("/maintainOwner/" + tempOrgids[0] + "/" + self.taskIds + "/maintainInspect/" + self.getCurrentOwner() + "/");
        }
      },
      //获取当前勾选的责任人
      getCurrentOwner: function () {
        let self = this;
        let hasOwnerEl = $("#maintainInspectList_" + self.getNewId + " input[type=checkbox]:checked");
        let ownerId = [-1];
        //单个任务才带责任人过去
        if (hasOwnerEl.length == 1) {
          let currentOwner = self.saveListOwner[hasOwnerEl[0].value];
          if (currentOwner) {
            ownerId = [currentOwner]
          }
        }
        return ownerId.toString();
      },
      //添加责任人成功
      finishAddOwner: function () {
        let self = this;
        self.getMaintainList();
        self.taskIds = "";
        jQuery("#selectCheckNum_" + self.getNewId).html(0);
        jQuery("#selectAll_" + self.getNewId).prop("checked", false);
      },
      //筛选 完成/未完成
      filterStatus: function (type) {
        if(!getClickEnabel()) return
        let self = this;
        self.pageIndex = 0;
        self.finishStatus = type;
        if (type == 1) {
          $("#maintainInspect_select_complete_" + self.getNewId).removeClass('statusFilter').addClass("selectStatusFilter");
          $("#maintainInspect_select_notComplete_" + self.getNewId).removeClass('selectStatusFilter').addClass("statusFilter");
        } else {
          $("#maintainInspect_select_complete_" + self.getNewId).removeClass('selectStatusFilter').addClass("statusFilter");
          $("#maintainInspect_select_notComplete_" + self.getNewId).removeClass('statusFilter').addClass("selectStatusFilter");
        }
        jQuery("#maintainInspectList_" + self.getNewId).empty();
        //self.reInit();
        self.getMaintainList();
      },
      //时间筛选
      getTbTime: function () {
        var self = this;
        loadSelectedDate_Fn(4, function (data) {
          self.startTime = data.startTime;
          self.endTime = data.endTime;
          var tempTimeYear = new Date(data.startTime.replace(/\-/g, "/")).getFullYear() + '年';
          var tempTimeMonth = (new Date(data.startTime.replace(/\-/g, "/")).getMonth() + 1) + '月'
          jQuery("#maintainInspect_select_dateRange_" + self.getNewId).addClass('select-active').html(tempTimeYear + tempTimeMonth);
          jQuery("#maintainInspectList_" + self.getNewId).empty();
          self.pageIndex = 0;
          //self.reInit();
          self.getMaintainList();
        }, self.startTime);
      },
      //完成范围进度条范围
      /* rangeSlider:function(){
         var self = this;
         var html=`<div class="block-title display-flex justify-content-space-between">范围 <span class="price-value" id="filter_rangeSlider_`+ self.getNewId+`">20 - 80</span></div>
               <div class="list simple-list">
               <ul>
               <li class="item-row">
                 <div class="item-cell width-auto flex-shrink-0">
                 </div>
                 <div class="item-cell item-cell-shrink-3">
                   <div
                     id="price_filter_v_`+ self.getNewId +`"
                     class="range-slider range-slider-init color-green"
                     data-label="true"
                     data-dual="true"
                     data-min="0"
                     data-max="100"
                     data-step="1"
                     data-value-left="20"
                     data-value-right="80"
                   ></div>
                 </div>
                 <div class="item-cell width-auto flex-shrink-0">
                 </div>
               </li>
             </ul>
           </div>`;
          layer.open({content: html
            ,success:function(){
            var range = app.range.create({
                 el: '#price_filter_v_'+ self.getNewId ,
                 on: {
                   change: function () {
                    
                   }
                 }
               })
            },btn: ['确定']
            ,yes: function(index, layero){
               self.startPercent = $("#filter_rangeSlider_" + self.getNewId).html().split(" - ")[0];
               self.endPercent = $("#filter_rangeSlider_" + self.getNewId).html().split(" - ")[1];
               self.pageIndex = 0;
               //self.reInit();
               self.getMaintainList();
               layer.closeAll();
            }
          }); 
          $('#price_filter_v_' + self.getNewId).on('range:change', function (e, range) {
              $("#filter_rangeSlider_" + self.getNewId).text((range.value[0])+' - '+(range.value[1]));
          });
      }, */
      //清空
      removeScreen: function () {
        let self = this;
        jQuery("#maintainInspect_select_org_" + self.getNewId).removeClass('select-active').html("选择单位");
        jQuery("#maintainInspect_select_owner_" + self.getNewId).removeClass('select-active').html("选择责任人");
        jQuery("#maintainInspect_select_progressRange_" + self.getNewId).removeClass('select-active').html("周期");
        jQuery("#maintainInspect_select_dateRange_" + self.getNewId).removeClass('select-active').html("选择日期范围");
        jQuery("#unitSearchTask_" + self.getNewId).val(null);
        self.maintainAccount = "";
        self.workPeriod=0
        self.taskTitle = "";
        self.startPercent = "";
        self.endPercent = "";
        self.startTime = "";
        self.endTime = "";
        self.finishStatus = "";
        self.selectOptionIndex = 0;
        self.pageIndex = 0;
        self.selectOptionOrg = '';
        self.gradeselectOptionIndex=''
        $("#maintainInspect_select_complete_" + self.getNewId).removeClass('selectStatusFilter').addClass("statusFilter");
        $("#maintainInspect_select_notComplete_" + self.getNewId).removeClass('selectStatusFilter').addClass("statusFilter");

        if (userInfor.isMuilUnitUser == 0) {
          self.currentOrgId = userInfor.organizationIds;
        } else {
          //多联网单位
          if (single_Orgid == "") {
            self.currentOrgId = userInfor.organizationIds;
          } else {
            self.currentOrgId = single_Orgid;
          }
        }
        $("#maintainInspectList_" + self.getNewId).empty();
        //self.reInit();
        self.getMaintainList();
      },
      //维保助手里面结束任务后，如果当前是在列表页面（保养，维保巡查，单点测试，联动测试）要刷新当前列表
      closeTaskBackRefreshList: function (e, done) {
        var self = this;
        var $ = self.$$;
        self.pageIndex = 0;
        $("#maintainInspectList_" + self.getNewId).empty();
        //self.reInit();
        self.getMaintainList();
      },
    },
    on: {
      pageInit: function (e, page) {
        let self = this;
        //区分联网单位
        self.isMuilUnitUser();
        //责任人
        self.initResponsPeople();
        //初始化搜索
        self.initEnter();

        if (self.selectIndex == 0) {  // 未开始
          self.status = 1;
        } else if (self.selectIndex == 1) { // 进行中
          self.status = 2;
        } else if (self.selectIndex == 2) {  // 已结束
          self.status = 3;
        } else {
          self.status = 0;
        }
        if (self.selectorgid == -1) {
          self.currentOrgId = userInfor.organizationIds;
        } else {
          self.currentOrgId = self.selectorgid;
        }
        //self.reInit();
        //重现筛选条件
        if (localStorage.getItem("ilink_select_option")) {
          var selectHistory = JSON.parse(localStorage.getItem("ilink_select_option"));
          if (selectHistory.page == "maintainInspect") {
            self.currentOrgId = selectHistory.organizationIds;
            jQuery("#maintainInspect_select_org_" + self.getNewId).html(selectHistory.orgName).addClass('select-active');
          }
        }
        self.updateListView(self.status);
      },
      pageBeforeOut: function (e, page) {
        var self = this;
        if (self.currentOrgId != userInfor.organizationIds) {
          let params = {
            page: 'maintainInspect',
            organizationIds: self.currentOrgId,
            orgName: jQuery("#maintainInspect_select_org_" + self.getNewId).html(),
          }
          saveSelectOption(params);
        }
      }
    }
  }

</script>